<template>
    <div class="app-container">
        <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="68px"
        >
            <el-form-item label="所属部门" prop="orgId">
                <treeselect
                    v-model="queryParams.orgId"
                    :options="deptOptions"
                    :show-count="true"
                    placeholder="请选择所属部门"
                    @keyup.enter.native="handleQuery"
                    style="width: 215px"
                />
            </el-form-item>
            <el-form-item label="姓名" prop="realName">
                <el-input
                    v-model="queryParams.realName"
                    placeholder="请输入姓名"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="员工类型" prop="political">
                <el-select
                    v-model="queryParams.staffType"
                    placeholder="请选择员工类型"
                    clearable
                >
                    <el-option
                        v-for="dict in dict.type.hrm_staff_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="社保方案" prop="pgmId">
                <el-select
                    v-model="queryParams.pgmId"
                    placeholder="请选择社保方案"
                    clearable
                >
                    <el-option
                        v-for="pgm in pgmList"
                        :key="pgm.id"
                        :label="pgm.name"
                        :value="pgm.id"
                    />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQuery"
                    >查询</el-button
                >
                <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQuery"
                    >重置</el-button
                >
            </el-form-item>
        </el-form>

        <TableCard>
            <el-table
                :border="Global.tableShowBorder"
                v-loading="loading"
                :data="salaryBookList"
                @selection-change="handleSelectionChange"
            >
                <el-table-column
                    label="姓名"
                    align="center"
                    prop="realName"
                    width="120"
                >
                    <template slot-scope="scope">
                        <router-link
                            :to="
                                '/hrm/staff/book/form/' +
                                scope.row.staffId +
                                '?readonly=1'
                            "
                            class="link-type"
                        >
                            <el-button type="text" size="small">{{
                                scope.row.realName
                            }}</el-button>
                        </router-link>
                    </template>
                </el-table-column>
                <el-table-column
                    label="部门"
                    align="center"
                    prop="deptName"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    label="职位"
                    align="center"
                    prop="postId"
                    :show-overflow-tooltip="true"
                >
                    <template slot-scope="scope">
                        <span>{{ parsePostName(scope.row.postId) }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="基本工资" align="center" prop="basic">
                    <template slot-scope="scope">
                        <span style="font-weight: 900; color: red">{{
                            util.toEsStr(scope.row.basic)
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="岗位工资" align="center" prop="post">
                    <template slot-scope="scope">
                        <span style="font-weight: 900; color: red">{{
                            util.toEsStr(scope.row.post)
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="职务工资"
                    align="center"
                    prop="position"
                >
                    <template slot-scope="scope">
                        <span style="font-weight: 900; color: red">{{
                            util.toEsStr(scope.row.position)
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="工资合计" align="center" prop="total">
                    <template slot-scope="scope">
                        <span style="font-weight: 900; color: red">{{
                            util.toEsStr(scope.row.total)
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="社保方案"
                    align="center"
                    prop="pgmId"
                    :show-overflow-tooltip="true"
                >
                    <template slot-scope="scope">
                        <div>{{ parsePgm(scope.row.pgmId) }}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="调薪原因"
                    align="center"
                    prop="adjustReason"
                    :show-overflow-tooltip="true"
                />
                <!--                <el-table-column label="住房补贴" align="center" prop="house" width="120"/>-->
                <!--                <el-table-column label="高温补贴" align="center" prop="temperature" width="120"/>-->
                <!--                <el-table-column label="交通补贴" align="center" prop="traffic" width="120"/>-->
                <!--                <el-table-column label="餐费补贴" align="center" prop="meal" width="120"/>-->
                <!--                <el-table-column label="话费补贴" align="center" prop="phone" width="120"/>-->
                <!--                <el-table-column label="绩效补贴" align="center" prop="performance" width="120"/>-->
                <!--                <el-table-column label="季度奖金" align="center" prop="quarter" width="120"/>-->
                <!--                <el-table-column label="月度奖金" align="center" prop="month" width="120"/>-->
                <!--                <el-table-column label="年度奖金" align="center" prop="year" width="120"/>-->
                <!--                <el-table-column label="全勤奖金" align="center" prop="attendance" width="120"/>-->
                <!--                <el-table-column label="内推奖金" align="center" prop="recommend" width="120"/>-->
                <!--                <el-table-column label="销售提成" align="center" prop="sale" width="120"/>-->
                <!--                <el-table-column label="计件工资" align="center" prop="calcCount" width="120"/>-->
                <!--                <el-table-column label="计时工资" align="center" prop="calcTime" width="120"/>-->
                <!--                <el-table-column label="工龄工资" align="center" prop="workAge" width="120"/>-->
                <!--                <el-table-column label="司龄工资" align="center" prop="comAge" width="120"/>-->
                <!--                <el-table-column label="职称工资" align="center" prop="professional" width="120"/>-->
                <!--                <el-table-column label="技能工资" align="center" prop="skill" width="120"/>-->
                <!--                <el-table-column label="学历工资" align="center" prop="education" width="120"/>-->
                <el-table-column
                    label="操作"
                    align="center"
                    class-name="small-padding fixed-width"
                    width="130"
                >
                    <template slot-scope="scope">
                        <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-edit"
                            @click="adjustSalary(scope.row)"
                            v-hasPermi="['hrm:salaryBook:edit']"
                        >
                            调薪
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>

            <pagination
                v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
            />
        </TableCard>

        <!-- 添加或修改工资档案对话框 -->
        <el-drawer
            :title="title"
            :visible.sync="open"
            :size="1000"
            append-to-body
            class="openForm"
        >
            <div class="salaryStaffInfo">
                <div>
                    <span>{{ form.realName }}</span
                    >/<span>{{ form.deptName }}</span
                    >/<span>{{ parsePostName(form.postId) }}</span>
                </div>
                <div>
                    <div style="font-weight: 900; color: red">
                        <span>合计：</span>{{ form.totalEs }}
                    </div>
                </div>
            </div>
            <el-divider></el-divider>
            <el-form
                ref="form"
                :model="form"
                :rules="rules"
                label-width="120px"
            >
                <el-col
                    :xs="24"
                    :sm="12"
                    :md="12"
                    :lg="12"
                    v-if="ifHave('basic')"
                >
                    <el-form-item label="基本工资" prop="basic">
                        <el-input
                            type="number"
                            v-model="form.basic"
                            placeholder="请输入基本工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="12"
                    :md="12"
                    :lg="12"
                    v-if="ifHave('post')"
                >
                    <el-form-item label="岗位工资" prop="post">
                        <el-input
                            type="number"
                            v-model="form.post"
                            placeholder="请输入岗位工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('position')">
                    <el-form-item label="职务工资" prop="position">
                        <el-input
                            type="number"
                            v-model="form.position"
                            placeholder="请输入职务工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    v-if="ifTypeHava('1')"
                >
                    <el-divider content-position="left">补贴</el-divider>
                </el-col>

                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('house')">
                    <el-form-item label="住房补贴" prop="house">
                        <el-input
                            type="number"
                            v-model="form.house"
                            placeholder="请输入住房补贴"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('temperature')">
                    <el-form-item label="高温补贴" prop="temperature">
                        <el-input
                            type="number"
                            v-model="form.temperature"
                            placeholder="请输入高温补贴"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('traffic')">
                    <el-form-item label="交通补贴" prop="traffic">
                        <el-input
                            type="number"
                            v-model="form.traffic"
                            placeholder="请输入交通补贴"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('meal')">
                    <el-form-item label="餐费补贴" prop="meal">
                        <el-input
                            type="number"
                            v-model="form.meal"
                            placeholder="请输入餐费补贴"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('phone')">
                    <el-form-item label="话费补贴" prop="phone">
                        <el-input
                            type="number"
                            v-model="form.phone"
                            placeholder="请输入话费补贴"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    v-if="ifTypeHava('2')"
                >
                    <el-divider content-position="left">浮动工资</el-divider>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('performance')">
                    <el-form-item label="绩效工资" prop="performance">
                        <el-input
                            type="number"
                            v-model="form.performance"
                            placeholder="请输入绩效补贴"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    v-if="ifTypeHava('3')"
                >
                    <el-divider content-position="left">奖金</el-divider>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('month')">
                    <el-form-item label="月度奖金" prop="month">
                        <el-input
                            type="number"
                            v-model="form.month"
                            placeholder="请输入月度奖金"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('quarter')">
                    <el-form-item label="季度奖金" prop="quarter">
                        <el-input
                            type="number"
                            v-model="form.quarter"
                            placeholder="请输入季度奖金"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('year')">
                    <el-form-item label="年度奖金" prop="year">
                        <el-input
                            type="number"
                            v-model="form.year"
                            placeholder="请输入年度奖金"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('attendance')">
                    <el-form-item label="全勤奖金" prop="attendance">
                        <el-input
                            type="number"
                            v-model="form.attendance"
                            placeholder="请输入全勤奖金"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('recommend')">
                    <el-form-item label="内推奖金" prop="recommend">
                        <el-input
                            type="number"
                            v-model="form.recommend"
                            placeholder="请输入内推奖金"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    v-if="ifTypeHava('4')"
                >
                    <el-divider content-position="left">提成工资</el-divider>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="12"
                    :md="12"
                    :lg="12"
                    v-if="ifHave('sale')"
                >
                    <el-form-item label="销售提成" prop="sale">
                        <el-input
                            type="number"
                            v-model="form.sale"
                            placeholder="请输入销售提成"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    v-if="ifTypeHava('5')"
                >
                    <el-divider content-position="left">计件工资</el-divider>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('calc_count')">
                    <el-form-item label="计件工资" prop="calcCount">
                        <el-input
                            type="number"
                            v-model="form.calcCount"
                            placeholder="请输入计件工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    v-if="ifTypeHava('6')"
                >
                    <el-divider content-position="left">计时工资</el-divider>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('calc_time')">
                    <el-form-item label="计时工资" prop="calcTime">
                        <el-input
                            type="number"
                            v-model="form.calcTime"
                            placeholder="请输入计时工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    v-if="ifTypeHava('7')"
                >
                    <el-divider content-position="left"
                        >工龄/司龄工资</el-divider
                    >
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('work_age')">
                    <el-form-item label="工龄工资" prop="workAge">
                        <el-input
                            type="number"
                            v-model="form.workAge"
                            placeholder="请输入工龄工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('com_age')">
                    <el-form-item label="司龄工资" prop="comAge">
                        <el-input
                            type="number"
                            v-model="form.comAge"
                            placeholder="请输入司龄工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="24"
                    :md="24"
                    :lg="24"
                    v-if="ifTypeHava('8')"
                >
                    <el-divider content-position="left">职称工资</el-divider>
                </el-col>
                <el-col
                    :xs="24"
                    :sm="12"
                    :md="12"
                    v-if="ifHave('professional')"
                >
                    <el-form-item label="职称工资" prop="professional">
                        <el-input
                            type="number"
                            v-model="form.professional"
                            placeholder="请输入职称工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('skill')">
                    <el-form-item label="技能工资" prop="skill">
                        <el-input
                            type="number"
                            v-model="form.skill"
                            placeholder="请输入技能工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" v-if="ifHave('education')">
                    <el-form-item label="学历工资" prop="education">
                        <el-input
                            type="number"
                            v-model="form.education"
                            placeholder="请输入学历工资"
                            @input="calcTatal"
                        >
                            <template slot="append">元</template>
                        </el-input>
                    </el-form-item>
                </el-col>

                <el-col :xs="24" :sm="24" :md="24" :lg="24">
                    <el-divider content-position="left">社保方案</el-divider>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12">
                    <el-form-item label="社保方案" prop="pgmId">
                        <el-select
                            v-model="form.pgmId"
                            placeholder="请选择社保方案"
                            clearable
                        >
                            <el-option
                                v-for="pgm in pgmList"
                                :key="pgm.id"
                                :label="pgm.name"
                                :value="pgm.id"
                            />
                        </el-select>
                    </el-form-item>
                </el-col>

                <el-col :xs="24" :sm="12" :md="12" :lg="12" v-show="false">
                    <el-form-item label="工资合计" prop="total">
                        <el-input
                            type="number"
                            v-model="form.total"
                            placeholder="请输入工资合计"
                        />
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="24" :lg="24">
                    <el-form-item label="调薪原因" prop="adjustReason">
                        <el-input
                            v-model="form.adjustReason"
                            type="textarea"
                            :rows="5"
                            placeholder="请输入内容"
                        />
                    </el-form-item>
                </el-col>
            </el-form>
            <div class="drawer-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-drawer>
    </div>
</template>

<script>
import {
    listSalaryBook,
    getSalaryBook,
    delSalaryBook,
    addSalaryBook,
    updateSalaryBook,
} from "@/api/hrm/salaryBook";
import { listSocialInsncPgmAll } from "@/api/hrm/socialInsncPgm";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listPostAll } from "@/api/system/post";
import { listSalaryItemConfig } from "@/api/hrm/salaryItemConfig";
export default {
    name: "SalaryBook",
    dicts: ["hrm_staff_type"],
    components: { Treeselect },
    data() {
        return {
            salaryConfigList: [],
            pgmList: [],
            // 遮罩层
            loading: true,
            // 部门树选项
            deptOptions: [],
            postList: [],
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示查询条件
            showSearch: true,
            // 总条数
            total: 0,
            // 工资档案表格数据
            salaryBookList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                orgId: null,
                realName: "",
                staffType: "",
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                basic: [
                    {
                        type: "number",
                        message: "请输入数字（单位元）",
                        trigger: "blur",
                        transform: (value) => {
                            value = (value + "").replace(/(^\s*)|(\s*$)/g, ""); // 先去除前后空格
                            return value || value === 0 ? Number(value) : ""; // 转为数字
                        },
                    },
                    {
                        required: true,
                        message: "基本工资不能为空",
                        trigger: "blur",
                    },
                ],
                pgmId: [
                    {
                        required: true,
                        message: "社保方案不能为空",
                        trigger: "blur",
                    },
                ],
            },
        };
    },
    created() {
        this.getPgmList();
        this.getSalaryConfigList();
        this.getTreeselect();
        this.getPostData();
        this.getList();
    },
    methods: {
        getPgmList() {
            listSocialInsncPgmAll().then((res) => {
                this.pgmList = res.data;
            });
        },
        getSalaryConfigList() {
            listSalaryItemConfig().then((res) => {
                this.salaryConfigList = res.data;
            });
        },
        /** 查询部门下拉树结构 */
        getTreeselect() {
            treeselect().then((response) => {
                this.deptOptions = response.data;
            });
        },
        getPostData() {
            listPostAll().then((res) => {
                this.postList = res.data;
            });
        },
        parsePostName(ids) {
            let nameArr = [];
            if (ids) {
                let selIds = ids.split(",");
                this.postList.forEach((item) => {
                    selIds.forEach((sel) => {
                        if (item.postId == sel) {
                            nameArr.push(item.postName);
                        }
                    });
                });
            }
            return nameArr.join(",");
        },
        /** 查询工资档案列表 */
        getList() {
            this.loading = true;
            listSalaryBook(this.queryParams).then((response) => {
                this.salaryBookList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                staffId: null,
                total: null,
                adjustReason: null,
                basic: null,
                post: null,
                position: null,
                house: null,
                temperature: null,
                traffic: null,
                meal: null,
                phone: null,
                performance: null,
                quarter: null,
                month: null,
                year: null,
                attendance: null,
                recommend: null,
                sale: null,
                calcCount: null,
                calcTime: null,
                workAge: null,
                comAge: null,
                professional: null,
                skill: null,
                education: null,
                createTime: null,
                createBy: null,
                updateBy: null,
                updateTime: null,
            };
            this.resetForm("form");
        },
        /** 查询按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.id);
            this.single = selection.length !== 1;
            this.multiple = !selection.length;
        },
        adjustSalary(row) {
            console.log(row);
            console.log(row.staffId);
            if (row.id != null) {
                this.handleUpdate(row);
            } else {
                this.handleAdd(row);
            }
        },
        /** 新增按钮操作 */
        handleAdd(row) {
            console.log(this.rules);
            this.reset();
            this.open = true;
            this.title = "定薪";
            this.form.staffId = row.staffId;
            this.form.realName = row.realName;
            this.form.postId = row.postId;
            this.form.deptName = row.deptName;
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const id = row.id || this.ids;
            getSalaryBook(id).then((response) => {
                this.form = response.data;
                this.open = true;
                this.title = "调薪";
                this.totalToEn();
            });
        },
        calcTatal() {
            this.form.total =
                Number(this.form.basic ? this.form.basic : 0) +
                Number(this.form.post ? this.form.post : 0) +
                Number(this.form.position ? this.form.position : 0) +
                Number(this.form.house ? this.form.house : 0) +
                Number(this.form.temperature ? this.form.temperature : 0) +
                Number(this.form.traffic ? this.form.traffic : 0) +
                Number(this.form.meal ? this.form.meal : 0) +
                Number(this.form.phone ? this.form.phone : 0) +
                Number(this.form.performance ? this.form.performance : 0) +
                Number(this.form.quarter ? this.form.quarter : 0) +
                Number(this.form.month ? this.form.month : 0) +
                Number(this.form.year ? this.form.year : 0) +
                Number(this.form.attendance ? this.form.attendance : 0) +
                Number(this.form.recommend ? this.form.recommend : 0) +
                Number(this.form.sale ? this.form.sale : 0) +
                Number(this.form.calcCount ? this.form.calcCount : 0) +
                Number(this.form.calcTime ? this.form.calcTime : 0) +
                Number(this.form.workAge ? this.form.workAge : 0) +
                Number(this.form.comAge ? this.form.comAge : 0) +
                Number(this.form.professional ? this.form.professional : 0) +
                Number(this.form.skill ? this.form.skill : 0) +
                Number(this.form.education ? this.form.education : 0);
            console.log(this.form.total);
            this.totalToEn();
        },
        totalToEn() {
            this.form.totalEs = this.util.toEsStr(this.form.total, true);
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    if (this.form.id != null) {
                        updateSalaryBook(this.form).then((response) => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addSalaryBook(this.form).then((response) => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal
                .confirm('是否确认删除工资档案编号为"' + ids + '"的数据项？')
                .then(function () {
                    return delSalaryBook(ids);
                })
                .then(() => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                })
                .catch(() => {});
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(
                "hrm/salaryBook/export",
                {
                    ...this.queryParams,
                },
                `salaryBook_${new Date().getTime()}.xlsx`
            );
        },
        ifHave(code) {
            let re = false;
            this.salaryConfigList.forEach((item) => {
                if (item.code == code) {
                    if (item.status == "0") {
                        re = true;
                    }
                }
            });
            return re;
        },
        ifTypeHava(type) {
            let re = false;
            this.salaryConfigList.forEach((item) => {
                if (item.type == type) {
                    if (item.status == "0") {
                        re = true;
                    }
                }
            });
            return re;
        },
        parsePgm(pgmId) {
            let name = "";
            this.pgmList.forEach((item) => {
                if (item.id == pgmId) {
                    name = item.name;
                }
            });
            return name;
        },
    },
};
</script>
<style lang="scss" scoped>
.salaryStaffInfo {
    padding: 0px 10px;
    position: fixed;
    background-color: #ffffff;
    z-index: 9999;
    width: calc(1000px - 40px);
    justify-content: space-between;
    flex-wrap: nowrap;
    display: flex;

    span {
        font-size: 14px;
        padding: 0px 10px;
        font-weight: 900;
        color: #444444;
    }
}
</style>
